<?php

define('IN_NETGORESP', true);

 /*
   ----------------------------------------------------------------------------------------------------
   INCLUSIONS
   ----------------------------------------------------------------------------------------------------
	+ Common.php
		- Includes all the other files needed.
   ----------------------------------------------------------------------------------------------------
   */
 include("common.php");

 /*
   ----------------------------------------------------------------------------------------------------
   REGISTRATION PAGE.
   ----------------------------------------------------------------------------------------------------
	- Lots of things that are explained further down.
   ----------------------------------------------------------------------------------------------------
   */
	if ($userrow == false) 
	{
 
		if (isset($_POST["register"])) 
		{
			$name = $_POST['name'];
			$password = $_POST['password'];
			$passwordag = $_POST['passwordag'];
			$email = $_POST['email'];
			$errors = 0;
			$errorlist = "";
				if ($name == "") { 
					$errors++; 
					$errorlist .= "<span style=color:red>* ".$lang['rNameReq']."</span><br />"; 
				}
				if ($password == "") 
				{ 
					$errors++; 
					$errorlist .= "<span style=color:red>* ".$lang['rPassReq']."</span><br />"; 
				}

				if ($email == "") 
				{ 
					$errors++; 
					$errorlist .= "<span style=color:red>* ".$lang['rEmailReq']."</span><br />"; 
				}				

			 /*
			   ----------------------------------------------------------------------------------------------------
			   REGISTRATION FORM CHECK
			   ----------------------------------------------------------------------------------------------------
			  	+ Check for errors (In order)
					+ Check for username length
						- If below 5 chars give error.
			  		+ Strip Junk characters
			  			- See if it matches original if not, error.
					+ Check for cussing, other.
						- If username includes them, error.
			  		+ Check to see if username is taken.
						- If it is, give error.
					+ Check password against re-entered password
						+ If error, they can't remember passwords easily..
							- Give huge error.
			  ----------------------------------------------------------------------------------------------------
			  */
			$subname = stripslashes($name);
			$subpass = stripslashes($password);
			$subemail = stripslashes($email); 
				if(strlen($subname) < 4 && empty($errorlist)) { $errors++; $errorlist .= "<span style=color:red>* ".$lang['rNameBelowMinChars']."</span><br />"; } else if(strlen($subname) > 30) { $errors++; $errorlist .= "<span style=color:red>* Username above 30 characters!</span><br />"; }
				if(strlen($subpass) < 4 && empty($errorlist)) { $errors++; $errorlist .= "<span style=color:red>* ".$lang['rPassBelowMinChars']."</span><br />"; } else if(strlen($subpass) > 30) { $errors++; $errorlist .= "<span style=color:red>* Password above 30 characters!</span><br />"; }
				
			$junk = array(',' , '/' , '\\' , '[' ,  ']' , '&', '^', '%', '$', '#', '!', '+', '(', ')', '|', '<', '>', ':', '"', '=', '@', '~','\'');
			$subname = trim($subname);
			$subpass = trim($subpass);
			$subemail = trim($subemail);
			$subname1 = str_replace($junk, '', $subname);
			$subpass1 = str_replace($junk, '', $subpass);

				if($subname1 != $subname && empty($errorlist))
				{ 
					$errors++; 
					$errorlist .= "<span style=color:red>* ".$lang['rNameInvalidChars']."</span><br />"; 
				}
				if($subpass1 != $subpass && empty($errorlist))
				{ 
					$errors++; 
					$errorlist .= "<span style=color:red>* ".$lang['rPassInvalidChars']."</span><br />"; 
				}

			$check = eregi($config['badwords'], $subname);

				if($check)
				{ 
					$errors++; 
					$errorlist .= "<span style=color:red>* ".$lang['rNameFoulLanguage']."</span><br />"; 
				}

		    $usernamequery = $db->sql_query("SELECT name FROM {{table}} WHERE name='$subname' LIMIT 1","account");

				if (mysql_num_rows($usernamequery) > 0) 
				{ 
					$errors++; 
					$errorlist .= "<span style=color:red>* ".$lang['rNameTaken']."</span><br />"; 
				}
		        if ($passwordag != $password && empty($errorlist))
				{ 
					$errors++; 
					$errorlist .= "<span style=color:red>* ".$lang['rPassValidationFailed']."</span><br />"; 
				}

			$password3 = md5($password);

		 /*
		   ----------------------------------------------------------------------------------------------------
		   NO ERRORS?!
		   ----------------------------------------------------------------------------------------------------
			+ Check to see if errors
				+ If errors
					- Go to show error list
				+ Else
					- Insert Userdata into mysql table!
		   ----------------------------------------------------------------------------------------------------
		   */
	    if($errors == 0)
      {
	      // Insert Data
				addNewUser($db, $name, $password3, $subemail);
				
				// @template: Header
			 	include("template/".$config['template_name']."/header.php");
				
				// @template: Register Page Success
				include("template/".$config['template_name']."/register.page.success.php");
				
				// @template: Footer
				include("template/".$config['template_name']."/footer.php");
				
	      echo $show;

	    } 
		else 
		{
			/*
			----------------------------------------------------------------------------------------------------
			ERROR LIST
			----------------------------------------------------------------------------------------------------
				+ Someone Tried to do some bad things here..
					- Prevent Hacking
					- Prevent Invalid Names
					- Prevent Everything else that isn't right from happening.
			----------------------------------------------------------------------------------------------------
			*/
			
			// @template: Header
			include("template/".$config['template_name']."/header.php");
			
			// @template: Register page error
			include("template/".$config['template_name']."/register.page.error.php");
			
			// @template: Footer
			include("template/".$config['template_name']."/footer.php");
			
		    echo $show;
	}
	/*
	----------------------------------------------------------------------------------------------------
	REGISTRATION FORM
	----------------------------------------------------------------------------------------------------
		+ Form of registration
			- Sets information into database and allows users to login to the site
			   and vbgore.
	----------------------------------------------------------------------------------------------------
	*/
	}
	else 
	{
  
		// @template: Header
		include("template/".$config['template_name']."/header.php");
		
		// @template: Registration page
		include("template/".$config['template_name']."/register.page.php");
		
		// @template: Footer
		include("template/".$config['template_name']."/footer.php");
		
		echo $page;
  }

 /*
   ----------------------------------------------------------------------------------------------------
   IF LOGGED IN...
   ----------------------------------------------------------------------------------------------------
	+ Prevents the following
		- Hacking Attempts
		- Stuck Users
		- Lost Users
   ----------------------------------------------------------------------------------------------------
   */
 } 
 else 
 {
 
	// @template: Header
	include("template/".$config['template_name']."/header.php");
	
	// @template: Registration page error
	include("template/".$config['template_name']."/register.page.error.php");
	
	// @template: Footer
	include("template/".$config['template_name']."/footer.php");

    echo $show;
}
?>